home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / 8bit / cislib_b / timers.act < prev    next >
Text File  |  1995-04-22  |  3KB  |  122 lines

  1. ;************************************
  2. ;*                                  *
  3. ;*(C)Copyright 1986 by Paul B. Loux *
  4. ;*                                  *
  5. ;* These routines are in the public *
  6. ;* domain,  and  are not to be sold *
  7. ;* for a profit. They may be freely *
  8. ;* distributed, provided  that this *
  9. ;* header remains in place. Use and *
  10. ;* enjoy! PBL, CIS 72337,2073.      *
  11. ;*                                  *
  12. ;************************************
  13. ;
  14. ; FILE: TIMERS.ACT
  15. ;
  16. ; This file contains a MODULE which 
  17. ; provides the  declarations needed
  18. ; to access the Atari OS timers. It
  19. ; includes the real-time  clock (or
  20. ; "jiffy counter") starting at $12,
  21. ; plus  the counters and  interrupt
  22. ; vectors for countdown timers 2-5. 
  23. ; In addition, a short demo program
  24. ; is provided to demonstrate how to
  25. ; install a timer-driven interrupt,
  26. ; and "multi-task" on your Atari.
  27. ;
  28. ; System timer 1 vectors are not in
  29. ; here, as they are used by the OS,
  30. ; to time I/O and other things.  It
  31. ; can be used in certain cases, but
  32. ; I try to get along without it.
  33. ;
  34. ;************************************
  35. ;
  36. ;     SIO system timer variables
  37. ;
  38. MODULE
  39. ;
  40. BYTE RTCLOK1=$12,   ; Real time clock
  41.      RTCLOK2=$13,
  42.      RTCLOK3=$14
  43.  
  44. CARD CDTMV2=$21A    ; SIO timer 2
  45. CARD CDTMV3=$21C    ; SIO timer 3
  46. CARD CDTMV4=$21E    ; SIO timer 4
  47. CARD CDTMV5=$220    ; SIO timer 5
  48.  
  49. CARD CDTMA2=$228    ; timer 2 vector
  50.  
  51. BYTE CDTMF3=$22A    ; timer 3 flag
  52. BYTE CDTMF4=$22C    ; timer 4 flag
  53. BYTE CDTMF5=$22E    ; timer 5 flag
  54. ;
  55. ;************************************
  56.  
  57. MODULE
  58.   CARD ctr,ctr2,limit
  59.  
  60.  
  61.  
  62. PROC SETCLOCK()        ; zero real-
  63.   RTCLOK1=0            ; time clock 
  64.   RTCLOK2=0
  65.   RTCLOK3=0
  66. RETURN
  67.  
  68.  
  69.  
  70. PROC READCLOCK()       ; show elapsed-
  71.                        ; time in jiffies
  72.   BYTE rt1,rt2,rt3
  73.  
  74.   rt1=RTCLOK1
  75.   rt2=RTCLOK2
  76.   rt3=RTCLOK3
  77.  
  78.   POSITION(10,20)
  79.   PRINTB(rt1) PRINT("  ") 
  80.   PRINTB(rt2) PRINT("  ") 
  81.   PRINTB(rt3) PRINT("  ") 
  82.  
  83. RETURN
  84.  
  85.  
  86.  
  87. PROC INTRPT()          ; timer IRQ routine
  88.   CDTMV2=limit         ; reset timer
  89.   ctr==+1              ; # times here
  90. RETURN
  91.  
  92.  
  93.  
  94. PROC TEST()
  95.   BYTE CH=764          ; keystroke pending
  96.   CARD save
  97.  
  98.   ctr=0  ctr2=0
  99.   limit=60             ; 60 jiffy wait
  100.  
  101.   save=CDTMA2          ; save old vector
  102.   SETCLOCK()           ; zero clock
  103.   CDTMA2=INTRPT        ; point vector
  104.   CDTMV2=limit         ; start countdown
  105.  
  106.   DO     
  107.    ctr2==+1
  108.    POSITION(10,10)
  109.    PRINTC(ctr)         ; # of timer IRQ's
  110.    POSITION(10,15)
  111.    PRINTC(ctr2)        ; # of times here
  112.    READCLOCK()         ; elapsed time
  113.   UNTIL CH#255         ; press any
  114.   OD                   ; key to stop
  115.  
  116.   limit=0
  117.   CDTMA2=save          ; restore vector
  118.   CH=255               ; clear keystroke
  119. RETURN
  120.   
  121.  
  122.